<?php
namespace app\commission\model;

use app\BaseModel;
use think\facade\Db;

class Wallet extends BaseModel
{
    //定义表名
    protected $name = 'longbing_card_commission_wallet';

    /**
     * @param $dis
     * @param $page
     * @功能说明:列表
     * @author chenniang
     * @DataTime: 2020-04-23 15:15
     */
    public function walletList($dis,$page){

        $data = $this->where($dis)->order('id desc')->paginate($page)->toArray();

        if(!empty($data['data'])){

            foreach ($data['data'] as &$v){
                //友好时间
                $f_time = datachange($v,'create_time');

                $v['create_time'] = $f_time['radar_group'].$f_time['radar_time'];

            }
        }
        return $data;
    }


    /**
     * @author chenniang
     * @DataTime: 2020-04-23 15:45
     * @功能说明:申请提现
     */
    public function walletAdd($data){

        $data['create_time'] = time();

        $data['update_time'] = time();

        $res = $this->insert($data);

        return $res;

    }


    /**
     * @author chenniang
     * @DataTime: 2020-04-23 16:51
     * @功能说明:编辑
     */
    public function walletUpdate($dis,$data){

        $data['update_time'] = time();

        $res = $this->where($dis)->update($data);

        return $res;

    }


    /**
     * @author chenniang
     * @DataTime: 2020-04-23 17:51
     * @功能说明:详情
     */
    public function walletInfo($dis){

        $data = $this->where($dis)->find();

        return !empty($data)?$data->toArray():[];

    }


    /**
     * @author chenniang
     * @DataTime: 2020-04-23 16:59
     * @功能说明:后台的提现记录列表
     */
    public function adminWalletList($dis,$mapor,$page){

        $data = $this->alias('a')
                ->join('longbing_card_user b','b.id = a.user_id','left')
                ->join('longbing_card_user_info c','a.user_id = c.fans_id','left')
                ->where($dis)
                ->where(function ($query) use ($mapor){
                    $query->whereOr($mapor);
                })
                ->field(['a.*','b.nickName','c.name as staff_name'])
                ->group('a.id')
                ->order('a.id desc')
                ->paginate($page)
                ->toArray();

        return $data;
    }










}